package itman.elm.utils;

import java.io.UnsupportedEncodingException;


public class CommonUtil {

    /**
     * 将字符串转换为 GBK 编码
     * @param source 待转换的字符串
     * @return
     */
    public static String chageEncode2GBK(String source){
        String str = "";
        try {
            str = new String(source.getBytes("ISO-8859-1"),"GBK");
        } catch (UnsupportedEncodingException e) {
            System.out.println("编码转换失败！");
            e.printStackTrace();
        }
        return str;
    }

    /**
     * 获取当前日期
     * @return 格式为 yyyy-MM-dd
     */
    public static String getCurrentDate(){
        String currentDate = "";
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
        currentDate = sdf.format(new java.util.Date());
        return currentDate;
    }

    /**
     * 获取当前日期时间
     * @return 格式为 yyyy-MM-dd HH:mm:ss
     */
    public static String getCurrentDateTime(){
        String currentDateTime = "";
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        currentDateTime = sdf.format(new java.util.Date());
        return currentDateTime;
    }

}
